package kuonjisai.swing.component;

import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import javax.swing.JLabel;
import java.awt.Insets;
import javax.swing.JTextField;
import java.awt.FlowLayout;

public class J26_SungJucNewData extends JDialog {
	private JTextField name;
	private JTextField kor;
	private JTextField eng;
	private JTextField mat;

	
	// 이름, 국어, 영어, 수학을  입력받음
	
	public J26_SungJucNewData( JFrame f) {
		
	super(f );
	setBounds(300, 300, 640, 480);
	setTitle("새 성적 만들기v1");
	setModalityType(DEFAULT_MODALITY_TYPE);
	getContentPane().setLayout(new BorderLayout(0, 0));
	
	JPanel panel = new JPanel();
	FlowLayout flowLayout = (FlowLayout) panel.getLayout();
	flowLayout.setVgap(15);
	getContentPane().add(panel, BorderLayout.SOUTH);
	
	JButton btnNewButton = new JButton("OK");
	btnNewButton.addActionListener(new ActionListener() {
		public void actionPerformed(ActionEvent e) {
		
		// 입력한 성적 데이터를 vo클래스에 저장
		SungJuckVO sj = new SungJukVO();
		sj.setName = (  Integer.parseInt(  name.getText()  ) );
		sj.setKor = ( kor.getText() );
		sj.setEng = ( eng.getText() );
		sj.setMat = ( mat.getText() );
		// vo에 저장되ㅏㄴ 데이터를
		// service 클래스의 insertSungJuk()에 전달
		if ( service.insertSungjuk( sj ) )
			 JOptionPane.showMessageDialog(null, "입력성공!");
		else 
			JOptionPane.showConfirmDialog(null, "입력실패");
		
		
		}
		
		
		
		
	});
	panel.add(btnNewButton);
	
	JButton btnNewButton_1 = new JButton("Cancle");
	btnNewButton_1.addActionListener(new ActionListener() {
		public void actionPerformed(ActionEvent e) {
			setVisible(false);
			dispose();
		}
	});
	panel.add(btnNewButton_1);
	
	JPanel panel_1 = new JPanel();
	getContentPane().add(panel_1, BorderLayout.CENTER);
	GridBagLayout gbl_panel_1 = new GridBagLayout();
	gbl_panel_1.columnWidths = new int[]{180, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
	gbl_panel_1.rowHeights = new int[]{120, 0, 0, 50, 0, 0, 0, 0, 0, 0, 0, 0};
	gbl_panel_1.columnWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, Double.MIN_VALUE};
	gbl_panel_1.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
	panel_1.setLayout(gbl_panel_1);
	
	JLabel titlelbl = new JLabel("성적을 입력하세요");
	GridBagConstraints gbc_titlelbl = new GridBagConstraints();
	gbc_titlelbl.gridwidth = 2;
	gbc_titlelbl.insets = new Insets(0, 0, 5, 5);
	gbc_titlelbl.gridx = 7;
	gbc_titlelbl.gridy = 2;
	panel_1.add(titlelbl, gbc_titlelbl);
	
	JLabel namelbl = new JLabel("이 름");
	GridBagConstraints gbc_namelbl = new GridBagConstraints();
	gbc_namelbl.insets = new Insets(0, 0, 5, 5);
	gbc_namelbl.gridx = 4;
	gbc_namelbl.gridy = 4;
	panel_1.add(namelbl, gbc_namelbl);
	
	name = new JTextField();
	GridBagConstraints gbc_name = new GridBagConstraints();
	gbc_name.insets = new Insets(0, 0, 5, 5);
	gbc_name.fill = GridBagConstraints.HORIZONTAL;
	gbc_name.gridx = 9;
	gbc_name.gridy = 4;
	panel_1.add(name, gbc_name);
	name.setColumns(10);
	
	JLabel korlbl = new JLabel("국 어");
	GridBagConstraints gbc_korlbl = new GridBagConstraints();
	gbc_korlbl.insets = new Insets(0, 0, 5, 5);
	gbc_korlbl.gridx = 4;
	gbc_korlbl.gridy = 6;
	panel_1.add(korlbl, gbc_korlbl);
	
	kor = new JTextField();
	GridBagConstraints gbc_kor = new GridBagConstraints();
	gbc_kor.insets = new Insets(0, 0, 5, 5);
	gbc_kor.fill = GridBagConstraints.HORIZONTAL;
	gbc_kor.gridx = 9;
	gbc_kor.gridy = 6;
	panel_1.add(kor, gbc_kor);
	kor.setColumns(10);
	
	JLabel englbl = new JLabel("영 어");
	GridBagConstraints gbc_englbl = new GridBagConstraints();
	gbc_englbl.insets = new Insets(0, 0, 5, 5);
	gbc_englbl.gridx = 4;
	gbc_englbl.gridy = 8;
	panel_1.add(englbl, gbc_englbl);
	
	eng = new JTextField();
	GridBagConstraints gbc_eng = new GridBagConstraints();
	gbc_eng.insets = new Insets(0, 0, 5, 5);
	gbc_eng.fill = GridBagConstraints.HORIZONTAL;
	gbc_eng.gridx = 9;
	gbc_eng.gridy = 8;
	panel_1.add(eng, gbc_eng);
	eng.setColumns(10);
	
	JLabel matlbl = new JLabel("수 학");
	GridBagConstraints gbc_matlbl = new GridBagConstraints();
	gbc_matlbl.insets = new Insets(0, 0, 0, 5);
	gbc_matlbl.gridx = 4;
	gbc_matlbl.gridy = 10;
	panel_1.add(matlbl, gbc_matlbl);
	
	mat = new JTextField();
	GridBagConstraints gbc_mat = new GridBagConstraints();
	gbc_mat.insets = new Insets(0, 0, 0, 5);
	gbc_mat.fill = GridBagConstraints.HORIZONTAL;
	gbc_mat.gridx = 9;
	gbc_mat.gridy = 10;
	panel_1.add(mat, gbc_mat);
	mat.setColumns(10);
	
		
		
		
		setVisible(true);
	
	}
	
	
	
} //  class
